﻿using System;
using System.Collections.Generic;
using System.Text;

namespace AMS.Configuration
{
    /// <summary>
    /// 列集合信息
    /// </summary>
    public class ColumnInfoCollection : ICollection<ColumnInfo>
    {
        private List<ColumnInfo> columns = new List<ColumnInfo>();

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="item"></param>
        public void Add(ColumnInfo item)
        {
            columns.Add(item);
            item.container = this;
        }

        public void Clear()
        {
            columns.Clear();
        }

        public bool Contains(ColumnInfo item)
        {
            return columns.Contains(item);
        }

        public void CopyTo(ColumnInfo[] array, int arrayIndex)
        {
            foreach (ColumnInfo column in columns)
            {
                array[arrayIndex++] = column;
            }
        }

        public int Count
        {
            get { return columns.Count; }
        }

        public bool IsReadOnly
        {
            get { return false; }
        }

        public bool Remove(ColumnInfo item)
        {
            return columns.Remove(item);
        }

        public IEnumerator<ColumnInfo> GetEnumerator()
        {
            return columns.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return columns.GetEnumerator();
        }

        internal int IndexOf(ColumnInfo item)
        {
            return columns.IndexOf(item);
        }

        internal int IndexOf(string columnName)
        {
            ColumnInfo item = this[columnName];
            return item == null ? -1 : item.Index;
        }

        public ColumnInfo this[int index]
        {
            get { return columns[index]; }
        }

        public ColumnInfo this[string columnName]
        {
            get
            {
                foreach (ColumnInfo item in columns)
                {
                    if (item.Name == columnName)
                    {
                        return item;
                    }
                }

                return null;
            }
        }
    }
}
